/**
 * 
 */
const path = require('path');
const express = require('express');
const bodyParser = require('body-parser');
const service = require('./service_old');

const app = express();

// (API) : http://www.expressjs.com.cn/4x/api.html#req.body
// for parsing application/json
app.use(bodyParser.json());
// for parsing application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: true }));

app.use('/static', express.static('public'));

app.get('/login', (req, resp)=>{
    // resp.render('/static/login.html');
    // resp.redirect('/static/login.html');
    resp.sendFile(path.join(__dirname, 'public', 'login.html'));
});

app.get('/index', (req, resp)=>{
    // resp.render('/static/index.html');
    // resp.redirect('/static/index.html');
    // resp.sendFile('/static/index.html');
    resp.sendFile(path.join(__dirname, 'public', 'index.html'));
});

app.get('/register', (req, resp)=>{
    // resp.render('/static/register.html');
    // resp.redirect('/static/register.html');
    resp.sendFile(path.join(__dirname, 'public', 'register.html'));
});

app.post('/check', service.doLogin);
app.post('/doLogin', service.doLogin);

app.post('/doRegister', service.doRegister);


app.listen(3000, ()=>{
    console.log('running ......');
});

